<template>
  <h2>当前求和：{{ sum }}</h2>
  <button @click="sum++">点我+1</button>
  <hr />
  <h2>当前信息为：{{ msg }}</h2>
  <button @click="msg += '!'">修改信息</button>
  <hr />
  <h2>姓名：{{ person.name }}</h2>
  <h2>年龄：{{ person.age }}</h2>
  <h2>薪资：{{ person.job.j1.salary }}K</h2>
  <button @click="person.name += '-'">修改姓名</button>
  <button @click="person.age++">增长年龄</button>
  <button @click="person.job.j1.salary++">增长薪资</button>
</template>
  
<script>
import { ref, reactive, computed, watch } from 'vue'
export default {
  name: 'App',
  setup() {
    let sum = ref(0)
    let msg = ref('你好啊')
    let person = ref({
      name: '张三',
      age: 19,
      job: {
        j1: {
          salary: 20,
        },
      },
    })

    watch(sum, (newValue, oldValue) => {
      console.log('sum值改变了', newValue, oldValue)
    })

    // 解决1
    /*  watch(person.value, (newValue, oldValue) => {
      console.log('persons值改变了', newValue, oldValue)
    })
    */

    // 解决2
    watch(
      person.value,
      (newValue, oldValue) => {
        console.log('persons值改变了', newValue, oldValue)
      },
      { deep: true }
    )
    // 返回一个对象
    return {
      sum,
      msg,
      person,
    }
  },
}
</script>  